package icu.funkye.service.impl;

import icu.funkye.controller.ProductController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import icu.funkye.entity.Product;
import icu.funkye.mapper.ProductMapper;
import icu.funkye.service.IProductService;

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    private final static Logger logger = LoggerFactory.getLogger(ProductServiceImpl.class);

    @Override
    public Boolean reduceStock(Integer id, Integer amount) {
        logger.info("product:id:{},数量{}",id,amount);
        Product product1 = this.getById(id);
        Product product = new Product(){{setStock(product1.getStock()-amount);setId(id);}};
        return this.updateById(product);
    }

    @Override
    public Boolean updateProduct(Product product) {
        logger.info("product:{}",product);
        return this.updateById(product);
    }

    @Override
    public Product getProduct(Integer id) {
        logger.info("获取商品库存id:{}",id);
        return this.getById(id);
    }
}
